﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ajayumi.Platform.WinForm.WorkSpace;

namespace ajayumi.Test.WinForm
{
    public partial class Form1 : Form, IParentContainer, IParentToolStripButtons
    {
        public Form1()
        {
            InitializeComponent();
        }

        #region IParentContainer
        public void SetTitle(string title)
        {

        }

        public void SetDescription(string desc)
        {

        }

        public void LoadToolStripItems(ToolStripItem[] toolStripItems)
        {
            foreach (ToolStripItem item in this.toolStripMain.Items)
            {
                //工具条中，退出 一直显示
                if (item == this.tsbtnExit) continue;

                int count = toolStripItems.Count<ToolStripItem>(o => { return o.Equals(item); });
                item.Visible = count > 0;
            }
        }

        public void SetEnabled(ToolStripItem control, bool value)
        {

        }

        public void RenderInContainer(WorkSpaceBase workspace)
        {
            ContainerControl containerControl = workspace.ContainerCtrl;
            TabPage tp = new TabPage(workspace.Title);
            tp.Controls.Add(containerControl);
            containerControl.Dock = DockStyle.Fill;
            this.tabControl1.TabPages.Add(tp);

            this.LoadToolStripItems(workspace.InitToolStripItems);
        }

        #endregion

        #region IParentToolStripButtons

        public ToolStripButton AddBtn
        {
            get { return this.tsbtnAdd; }
        }

        public ToolStripSeparator Separator4
        {
            get { return this.tssep4; }
        }

        public ToolStripButton ExitBtn
        {
            get { return this.tsbtnExit; }
        }

        #endregion

        internal void CloseTabPage()
        {
            this.tabControl1.SelectedTab.Dispose();
            WorkSpacesManager.Instance.Remove("Test1");
            this.LoadToolStripItems(new ToolStripItem[] { });
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.LoadToolStripItems(new ToolStripItem[] { });
        }

        private void tsmiTest_Click(object sender, EventArgs e)
        {
            WorkSpacesManager.Instance.ShowModule("Test1", this);
        }

        private void tsmiTest2_Click(object sender, EventArgs e)
        {

        }



    }
}
